package com.xydtech.common;


import com.xydtech.common.core.domain.entity.SysDept;
import com.xydtech.common.enums.ApiContant;
import com.xydtech.common.model.ResponseModel;
import com.xydtech.data.DataPlatHttpUtils;
import com.xydtech.ecard.user.domain.EcardApiUserInfo;
import com.xydtech.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 电子名片天眼查企业接口调用
 *
 * @author yuzhiguo
 * @date 2024/7/25 上午10:36
 */
@Component
public class EcardOrgInfoApiCommon {
    @Autowired
    private DataPlatHttpUtils dataPlatHttpUtils;
    @Autowired
    private ISysDeptService sysDeptService;

    public ResponseModel getOrgInfoByApi(EcardApiUserInfo user, String apiNum, String entName, String entOrgCode) {
        try {
            /**根据执行机构查询法人机构，如果没有则取当前机构*/
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(user.getDeptId());
            /**接口参数*/
            Map<String, Object> param = new HashMap<>();
            param.put("name", entName);
            param.put("idCardNumber", entOrgCode);
            ResponseModel responseModel = dataPlatHttpUtils.dataPlatRequest(apiNum, "", ApiContant.APPLETTYPE_ECARD, dept.getDeptId(), param);
            return responseModel;
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseModel(-1, "企业信息下载接口调用失败：" + e.toString() + e.getMessage());
        }
    }
}